package com.paic.mhis.hcpms.trust.intergration.sao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.paic.mhis.hcpms.evaluation.common.constants.EvaluationConstants;
import com.paic.mhis.hcpms.evaluation.intergration.dto.FwaOrgDTO;
import com.paic.mhis.hcpms.trust.intergration.sao.FwaDoctorSao;
import com.paic.pafa.app.integration.sa.PafaSAOException;
import com.paic.pafa.appclient.IServiceClient;
import com.paic.pafa.appclient.ServiceParams;
import com.paic.pafa.appclient.ServiceResults;
import com.paic.pafa.appclient.annotation.ActionClient;
import com.paic.pafa.biz.sao.BaseSAO;

/**
 * 医务人员FWA 接口辅助类
 * @author EX-CHENLIN600
 *
 */
@Component("fwaDoctorSao")
public class FwaDoctorSaoImpl extends BaseSAO implements FwaDoctorSao {
	
	private Log log = LogFactory.getLog(FwaDoctorSaoImpl.class);

	// 在不同weblogic下调用
//	 @ActionClient(name = "mhis.fwa.doctorInfoHonestyESA", pafaAc = "${mhis.fwa.pafaAc}")
	// 在同一个weblogic下调用
	@ActionClient(name = "mhis.fwa.doctorInfoHonestyESA", pafaAc = "${web.defaultPafaAcClient}")
	private IServiceClient serviceClient;

	@Override
	public Map<String, Object>  invokeDoctorInfoESA(String doctorCode, String startDate, String endDate)
			throws PafaSAOException {
		Map<String, Object> map = new HashMap<String, Object>();
		ServiceParams params = ServiceParams.newInstance();
		params.set("doctorCode", doctorCode);
		params.set("startDate", startDate);
		params.set("endDate", endDate);
		//调FWA接口
		ServiceResults result = serviceClient.invoke(params);
		log.info("===========医务人员调FWA接口返回的数据=========="+result);
		
		List<FwaOrgDTO> list =new ArrayList<FwaOrgDTO>();
		
		@SuppressWarnings("rawtypes")
		Map mapRes = (Map)result.get("map");
		
		String suspiciousNum = "0";//可疑条数
		String suspiciousAmount = "0";//可疑金额
		String highlySuspiciousNum = "0";//高度可疑条数 
		String highlySuspiciousAmount = "0";//高度可疑金额 
		String outOfLineNum = "0";//违规条数     
		String outOfLineAmount = "0";//违规金额     
		String numTotal = "0";//单据总条数   
		String amountTotal = "0";//单据涉及金额 
		String advanceFront = "0";//事前提醒条数 
		String advanceAmong = "0";//事中提醒条数 
		String suspiciousPersonNum = "0";//可疑人次
		String highlySuspiciousPersonNum = "0";//高度可疑人次
		String outOfLinePersonNum = "0"; //违规人次
		
		if(mapRes.get("suspiciousNum")!=null){
			suspiciousNum = mapRes.get("suspiciousNum")+"";
		}
		if(mapRes.get("suspiciousAmount")!=null){
			suspiciousAmount = mapRes.get("suspiciousAmount")+"";
		}
		if(mapRes.get("highlySuspiciousNum")!=null){
			highlySuspiciousNum =  mapRes.get("highlySuspiciousNum")+"";
		}
		if(mapRes.get("highlySuspiciousAmount")!=null){
			highlySuspiciousAmount =  mapRes.get("highlySuspiciousAmount")+"";
		}
		if(mapRes.get("outOfLineNum")!=null){
			outOfLineNum = mapRes.get("outOfLineNum")+"";
		}
		if(mapRes.get("outOfLineAmount")!=null){
			outOfLineAmount = mapRes.get("outOfLineAmount")+"";
		}
		if(mapRes.get("numTotal")!=null){
			numTotal = mapRes.get("numTotal")+"";
		}
		if(mapRes.get("amountTotal")!=null){
			amountTotal =  mapRes.get("amountTotal")+"";
		}
		if(mapRes.get("advanceFront")!=null){
			advanceFront = mapRes.get("advanceFront")+"";
		}
		if(mapRes.get("advanceAmong")!=null){
			advanceAmong = mapRes.get("advanceAmong")+"";
		}
		if(mapRes.get("suspiciousPersonNum")!=null){
			suspiciousPersonNum = mapRes.get("suspiciousPersonNum")+"";
		}
		if(mapRes.get("highlySuspiciousPersonNum")!=null){
			highlySuspiciousPersonNum = mapRes.get("highlySuspiciousPersonNum")+"";
		}
		if(mapRes.get("outOfLinePersonNum")!=null){
			outOfLinePersonNum = mapRes.get("outOfLinePersonNum")+"";
		}
		
		
		FwaOrgDTO fod = new FwaOrgDTO();
		fod.setName("可疑");
		fod.setResult(EvaluationConstants.SUSPICIOUS_NO);
		fod.setNum(suspiciousNum);
		fod.setMoney(suspiciousAmount);
		list.add(fod);
		
		fod = new FwaOrgDTO();
		fod.setName("高度可疑");
		fod.setResult(EvaluationConstants.HIGHLYSUSPICIOUS_NO);
		fod.setNum(highlySuspiciousNum);
		fod.setMoney(highlySuspiciousAmount);
		list.add(fod);
		
		fod = new FwaOrgDTO();
		fod.setName("违规");
		fod.setResult(EvaluationConstants.OUTOFLINE_NO);
		fod.setNum(outOfLineNum);
		fod.setMoney(outOfLineAmount);
		list.add(fod);
		map.put("advanceFront", advanceFront);
		map.put("advanceAmong", advanceAmong);
		map.put("numTotal", numTotal);
		map.put("amountTotal", amountTotal);
		map.put("suspiciousPersonNum", suspiciousPersonNum);
		map.put("highlySuspiciousPersonNum", highlySuspiciousPersonNum);
		map.put("outOfLinePersonNum", outOfLinePersonNum);
		map.put("list", list);
		return map;
	}

}
